﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PM.Web
{
    public partial class GovNewsList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindDropdownlist();
                bindData();
            }
        }

        private void bindDropdownlist()
        {
            DataAccess.PmData dal = new DataAccess.PmData();
            this.ddlGovList.DataSource = dal.GetGovAccount(Common.GetCommunityCode(), null);
            this.ddlGovList.DataBind();
            this.ddlGovList.Items.Insert(0, new ListItem("--选择机构--", "0"));

            if (!string.IsNullOrEmpty(Request.QueryString["gid"]))
            {
                try
                {
                    this.ddlGovList.Items.FindByValue(Request.QueryString["gid"]).Selected = true;
                }
                catch
                { }
            }
        }

        private void bindData()
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            DataAccess.PmData dal = new DataAccess.PmData();
            dt = dal.GetGovNewsList(Common.GetCommunityCode(), int.Parse(this.ddlGovList.SelectedValue), null, null);
            AspNetPager1.RecordCount = dt.Rows.Count;
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.DataSource = dt.DefaultView;
            this.repGovNewsList.DataSource = pds;
            this.repGovNewsList.DataBind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            bindData();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindData();
        }
    }
}